//
//  UIView+Frame.m
//  TouchTV
//
//  Created by rhc on 16/9/14.
//  Copyright © 2016年 AceWei. All rights reserved.
//

#import "UIView+Layout.h"

@implementation UIView (Layout)
@dynamic top;
@dynamic bottom;
@dynamic left;
@dynamic right;

@dynamic width;
@dynamic height;

@dynamic size;

@dynamic x;
@dynamic y;

- (CGFloat)top
{
    return self.frame.origin.y;
}

- (void)setTop:(CGFloat)top
{
    CGRect frame = self.frame;
    frame.origin.y = top;
    self.frame = frame;
}

- (CGFloat)left
{
    return self.frame.origin.x;
}

- (void)setLeft:(CGFloat)left
{
    CGRect frame = self.frame;
    frame.origin.x = left;
    self.frame = frame;
}

- (CGFloat)bottom
{
    return self.frame.size.height + self.frame.origin.y;
}

- (void)setBottom:(CGFloat)bottom
{
    CGRect frame = self.frame;
    frame.origin.y = bottom - frame.size.height;
    self.frame = frame;
}

- (CGFloat)right
{
    return self.frame.size.width + self.frame.origin.x;
}

- (void)setRight:(CGFloat)right
{
    CGRect frame = self.frame;
    frame.origin.x = right - frame.size.width;
    self.frame = frame;
}

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (void)setX:(CGFloat)value
{
    CGRect frame = self.frame;
    frame.origin.x = value;
    self.frame = frame;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (void)setY:(CGFloat)value
{
    CGRect frame = self.frame;
    frame.origin.y = value;
    self.frame = frame;
}

- (CGPoint)origin
{
    return self.frame.origin;
}

- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}

- (CGFloat)centerX
{
    return self.center.x;
}

- (void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

- (CGFloat)width
{
    return self.frame.size.width;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}
@end



@implementation UIView (SetLines)

//- (void)setBottomLineWithColor:(UIColor *)color {
//    UIView *line = [[UIView alloc] init];
//    line.backgroundColor = color;
//    [self addSubview:line];
//    [line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.bottom.right.offset(0);
//        make.height.mas_equalTo(1);
//    }];
//}
//
//- (void)setTopLineWithColor:(UIColor *)color {
//    UIView *line = [[UIView alloc] init];
//    line.backgroundColor = color;
//    [self addSubview:line];
//    [line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.offset(0);
//        make.height.mas_equalTo(1);
//    }];
//}
//
//- (void)setRightLineWithColor:(UIColor *)color {
//    UIView *line = [[UIView alloc] init];
//    line.backgroundColor = color;
//    [self addSubview:line];
//    [line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.right.offset(0);
//        make.width.mas_equalTo(1);
//    }];
//}
//
//- (void)setLeftLineWithColor:(UIColor *)color {
//    UIView *line = [[UIView alloc] init];
//    line.backgroundColor = color;
//    [self addSubview:line];
//    [line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.offset(0);
//        make.width.mas_equalTo(1);
//    }];
//}
//- (void)setBottomLineWithColor:(UIColor *)lineColor lineHeight:(CGFloat)lineHeight marginLeft:(CGFloat)marginLeft marginRight:(CGFloat)marginRight{
//    UIView *bottomSepatatorView = [UIView new];
//    bottomSepatatorView.backgroundColor = lineColor;
//    [self addSubview:bottomSepatatorView];
//    [bottomSepatatorView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.offset(0);
//        make.left.offset(marginLeft);
//        make.right.offset(-marginRight);
//        make.height.mas_equalTo(lineHeight);
//    }];
//}
//
//- (void)setTopLineWithColor:(UIColor *)lineColor lineHeight:(CGFloat)lineHeight  marginLeft:(CGFloat)marginLeft marginRight:(CGFloat)marginRight{
//    UIView *topSepatatorView = [UIView new];
//    topSepatatorView.backgroundColor = lineColor;
//    [self addSubview:topSepatatorView];
//    [topSepatatorView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(0);
//        make.left.offset(marginLeft);
//        make.right.offset(-marginRight);
//        make.height.mas_equalTo(lineHeight);
//    }];
//}
@end
